<template>
  <section>
    <div class="custorm--modelbox graphicnavlist-edit">
      <!-- <choose-path ref="choosepath" :changeEvt="chooseUrl" :tabType="tabType"></choose-path> -->
      <renohome-right-nav
        :custormItemData="custormItemData"
        @rightNavChange="rightNavChange"
      ></renohome-right-nav>
      <section>
        <div class="edit-form-item">
          <div class="form-label mb-20">选择样式</div>
          <el-radio-group
            v-model="custormItemData.style.display"
            class="flex-row mar-15"
          >
            <el-radio label="1">图标+文字</el-radio>
            <el-radio label="2">文字</el-radio>
          </el-radio-group>
        </div>
        <div class="edit-form-item">
          <div class="form-label mb-20">边角样式</div>
          <el-radio-group
            v-model="custormItemData.style.radius"
            class="flex-row mar-15"
          >
            <el-radio label="1">直角</el-radio>
            <el-radio label="2">圆角</el-radio>
          </el-radio-group>
        </div>
        <div class="edit-form-item">
          <div class="form-label">上下边距</div>
          <div class="flex-row flex-align-c">
            <el-slider
              :show-tooltip="false"
              style="width: 70%;"
              v-model="margincol"
              input-size="mini"
              :max="48"
            >
            </el-slider>
            <div class="coupon-showslider">{{custormItemData.style.margincol}}px</div>
          </div>
          <div class="form-label">左右边距</div>
          <div class="flex-row flex-align-c">
            <el-slider
              :show-tooltip="false"
              style="width: 70%;"
              v-model="marginrow"
              input-size="mini"
              :max="48"
            >
            </el-slider>
            <div class="coupon-showslider">{{custormItemData.style.marginrow}}px</div>
          </div>
        </div>

        <div class="es-form-item">
          <div
            v-for="(item, index) in custormItemData.data"
            :key="index"
            style="padding-top: 20px;"
          >
            <div
              class="item"
              draggable="false"
              style="margin-bottom:0;"
            >
              <i
                class="el-icon-circle-close  delete-child"
                @click="delItemList({data:custormItemData.data,index})"
              ></i>
              <div class="item-inner "><span class="labeltext">图标</span>
                <div
                  show="0"
                  class="small"
                  style="align-self: start;"
                >
                  <div class="uploadSource solid"><i
                      class="delete ivu-icon iconfont icon-input_clear"
                      style="font-size: 16px;"
                    ></i>
                    <div
                      class="img"
                      @click="uploadtoggle(index,'image')"
                      :style="{'background-image':`url(${getPath(item.thumb.file_path)})`,'height':'50px','background-repeat':'no-repeat','background-size':'cover','background-position':'50%'}"
                    ></div>
                  </div>
                </div>
              </div>

              <div class="item-inner ">
                <span class="labeltext">标题</span>
                <el-input
                  v-model="item.title"
                  size="mini"
                  style="width: 0;flex-grow: 1;"
                ></el-input>
              </div>
              <div class="item-inner ">
                <span class="labeltext">链接</span>
                <div
                  class="readonly-div"
                  @click="uploadtoggle(index,'link')"
                >
                  <div class="readonly ivu-input-wrapper ivu-input-wrapper-default ivu-input-type">
                    <input
                      autocomplete="off"
                      spellcheck="false"
                      type="text"
                      placeholder="请选择链接"
                      readonly="readonly"
                      class="ivu-input ivu-input-default"
                      :value="typeof item.link === 'string' ? item.link : item.link.path"
                    >
                  </div> <i
                    class="icon icon-fujian readonly-icon"
                    style="left: 12px;margin-top:-3px;"
                  ></i>
                </div>
              </div>
            </div>

          </div>
          <div
            class="goodscol-add"
            @click="addItemList({data:custormItemData.data,itemCopy:{title: '这里是主标题',icon: 'icon icon-qiehuan',link: '',thumb: {file_path: 'default_btn1.png'}}})"
            style="margin-top:20px;"
          > +添加 </div>
        </div>
      </section>
      <!-- <section v-if="fgActive"></section> -->
    </div>
  </section>
</template>

<script>
//  import choosePath from "../../components/choosePath"
import defaultConfig from './utils/editConfig'
export default {
  mixins: [defaultConfig.mixins],
  props: {
    defaultConfig: {
      type: Object,
      default: function() {
        return defaultConfig
      }
    }

  },
  data() {
    return {}
  },
  computed: {
    margincol: {
      set(value) {
        this.custormItemData.style.margincol = value
      },
      get() {
        return this.conversionType('number', this.custormItemData.style.margincol)
      }
    },
    marginrow: {
      set(value) {
        this.custormItemData.style.marginrow = value
      },
      get() {
        return this.conversionType('number', this.custormItemData.style.marginrow)
      }
    }
  },
  methods: {
    uploadFileCallBack(files) {
      const { key } = files
      if (key === 'ChooseLink') {
        const { currentRow: [file_path], displayData: [custorm] } = files
        if (this.imgCurrent !== -1 && file_path) {
          this.custormItemData.data[this.imgCurrent]['link'] = file_path
        } else {
          if (custorm) {
            this.custormItemData.data[this.imgCurrent]['link'] = custorm
          } else {
            this.$message.error('请选择链接~!')
          }
        }
      } else {
        const { displayData: [file_path] } = files
        if (this.imgCurrent !== -1 && file_path) {
          this.custormItemData.data[this.imgCurrent]['thumb'] = file_path
        }
      }
    },
    uploadtoggle(index, type) {
      var data = this.custormItemData.data[index]['link']
      this.output({ type, params: { editKey: this.custormItemData.key }, data })
      this.imgCurrent = index
    }
  }
}
</script>

<style lang="scss" scoped>
.custorm--modelbox.graphicnavlist-edit {
  //列表开始
  .es-form-item {
    border-bottom: 5px solid #f6f7f9;
    padding: 20px 23px;
    font-size: 12px;

    .uploadSource {
      background: #fff;
      cursor: pointer;
    }

    .uploadSource {
      width: 50px;
      height: 50px;
      line-height: 50px;
      margin-right: 0;
      border: 1px dashed #ededed;
      text-align: center;
      color: #dad9d9;
      background-size: 100% 100%;
      background-repeat: no-repeat;
      float: left;
      position: relative;
    }
  }

  .es-form-item:last-child {
    border-bottom: 0;
  }

  .es-form-item .item-inner {
    margin-top: 8px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .es-form-item .item-inner:first-of-type {
    margin-top: 0;
  }

  .es-form-item .button-img {
    width: 32px;
    height: 32px;
    margin-right: 20px;
    cursor: pointer;
    border-radius: 4px;
    box-sizing: border-box;
    line-height: 36px;
    text-align: center;
    border: 1px solid transparent;
  }

  .es-form-item .button-img.block {
    width: 100%;
    position: relative;
    min-height: 32px;
    height: auto;
    padding: 10px;
    text-align: left;
  }

  .es-form-item .button-img.active {
    border-color: #fb6638 !important;
  }

  .es-form-item .alignC {
    text-align: center;
  }

  .es-form-item .item {
    background: #f6f7f9;
    padding: 10px 20px 10px 10px;
    border: 1px solid #eee;
    color: #999;
    position: relative;
  }

  .es-form-item .labeltext {
    width: 40px;
    text-align: right;
    padding-right: 8px;
    color: #666;
  }

  .es-form-item .item-inner .readonly-div {
    position: relative;
    flex-grow: 1;
  }

  .ivu-input-wrapper {
    display: inline-block;
    width: 100%;
    position: relative;
    vertical-align: middle;
    line-height: normal;
  }

  .ivu-input {
    display: inline-block;
    width: 100%;
    height: 32px;
    line-height: 1.5;
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid #ededed;
    border-radius: 4px;
    color: #333;
    background-color: #fff;
    background-image: none;
    position: relative;
    cursor: text;
    -webkit-transition: border 0.2s ease-in-out, background 0.2s ease-in-out,
      -webkit-box-shadow 0.2s ease-in-out;
    transition: border 0.2s ease-in-out, background 0.2s ease-in-out,
      box-shadow 0.2s ease-in-out;
  }

  .es-form-item .item-inner .readonly-div .readonly input {
    background: #e8effc;
    border: 0;
    padding-left: 18px;
    cursor: pointer;
    box-sizing: border-box;
  }

  .es-form-item .item-inner .readonly-div .readonly-icon {
    position: absolute;
    top: 5px;
    left: 12px;
  }

  .es-form-item .item .delete-child {
    position: absolute;
    right: 4px;
    top: 0;
    cursor: pointer;
    font-size: 14px;
  }

  //列表结束

  //风格开始
  .es-listmenu {
    padding: 0 6px;
    margin: 0 12px;
    border-bottom: 1px solid #ededed;
    height: 50px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    font-size: 14px;
    color: #333;
  }

  .es-listmenu .icon {
    margin-right: 10px;
  }

  .es-listmenu .text {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
  }

  .es-listmenu .remark {
    color: #999;
  }

  .es-listmenu .remark i {
    font-size: 14px;
  }

  //风格结束
}
</style>
